package net.zoneland.knowledge.dao;

import net.zoneland.knowledge.model.AttachmentPreviewAppKey;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

@Mapper
public interface AttachmentPreviewAppKeyMapper {


    @Insert({
            "INSERT INTO AITK_PARTY_PREVIEW_APPKEY (ID,APP_KEY,STATUS) ",
            "values (#{id,jdbcType=VARCHAR}, #{appKey,jdbcType=VARCHAR}, #{status,jdbcType=DECIMAL})"
    })
    int insert(AttachmentPreviewAppKey previewAppKey);

    @Select({
        "SELECT ID,APP_KEY,CREATE_TIME,STATUS FROM (" +
                "SELECT AP.ID,AP.APP_KEY,AP.CREATE_TIME,AP.STATUS FROM AITK_PARTY_PREVIEW_APPKEY AP WHERE AP.STATUS=1 ORDER BY CREATE_TIME DESC" +
         ") WHERE ROWNUM = 1",
    })
    @Results({
        @Result(column="ID", property="id", jdbcType=JdbcType.VARCHAR, id=true),
        @Result(column="APP_KEY", property="appKey", jdbcType=JdbcType.VARCHAR),
        @Result(column="CREATE_TIME", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="STATUS", property="status", jdbcType=JdbcType.DECIMAL)
    })
    AttachmentPreviewAppKey selectAppKey();

    @Update({
        "update AITK_PARTY_PREVIEW_APPKEY ",
        "set status = 0 ",
        "where ID = #{id,jdbcType=VARCHAR}"
    })
    int updateByPrimaryKey(String id);
}